package com.example.commons.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @auther zcy
 * @data 2020/1/3 16:25
 */
@Configuration
public class CrossConfig implements WebMvcConfigurer {
    //     response.setHeader("Access-Control-Allow-Origin","*");
//        response.setHeader("Access-Control-Allow-Credentials","true");
//        response.setHeader("Access-Control-Allow-Methods","POST,GET,OPTIONS,PUT,DELETE,PATCH,HEAD");
//        response.setHeader("Access-Control-Allow-Max-Age","3600");
//        response.setHeader("Access-Control-Allow-Headers","*");
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")    // 允许跨域访问的路径
                .allowedOrigins("*")    // 允许跨域访问的源
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")    // 允许请求方法
                .maxAge(168000)    // 预检间隔时间
                .allowedHeaders("*")  // 允许头部设置
                .allowCredentials(true);    // 是否发送cookie
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

//        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/v2/api-docs", "/swagger-resources/configuration/ui", "/swagger-resources", "/swagger-resources/configuration/security", "/swagger-ui.html/**", "/course/coursebase/**", "/webjars/**", "/druid/**", "/login", "/webjars/springfox-swagger-ui/**", "/captcha.jpg**", "/actuator/**", "/file/**", "/sysData/selectOneSysData", "/file/getImage", "/stationDataB1_SC/import/template", "/stationDataB2_SW", "/stationDataB3_ZZ/import/template", "/stationDataHumanB4/import/template", "/stationDataDwB5/import/template", "/stationDataMsgB6/import/template", "/stationDataB7_UAV/import/template", "/stationDataD6_GD/import/template", "/stationDataD7_JC/import/template", "/user/saveUser", "/user/checkLoginName", "/mapUrl/selectAllMapUrl", "/station/getIndexMapStationTree", "/stationMonitorConfig/selectAllStationMonitorConfig", "/stationData/getIndexStationsAndStationData", "/sysData/selectOneSysData", "/webSocket/**", "/socket/**", "/webSocket/info", "/email/updateEmail");
    }

}
